package com.hare.harelearn.DataStructure.ArrayAlgorithm;

public class 数组中的最长山脉 {

    public static void main(String[] args) {
        System.out.println(longestMountain(new int[]{2,1,4,7,4,3,2,7,1}));
    }

    public static int longestMountain(int[] arr) {
        int n = arr.length;
        if (n == 0) {
            return 0;
        }
        int count = 0;
        for (int i = 1; i < arr.length; i++) {
            if(arr[i] > arr[i-1]){
                count++;
            } else {
                continue;
            }
        }
        for (int i = arr.length-2; i >=0; i--) {
            if(arr[i] < arr[i+1]){
                count++;
            } else {
                continue;
            }
        }
        return count-1;
    }
}
